<?php 
defined ('_JEXEC') or die ('Restricted access');
jimport( 'joomla.application.component.model' );
class HotrosModelHotros extends JModel{
	var $_data = null ;
	var $_pagination = null;
	function _buildQuery(){
		$orderby = $this->_buildContentOrderBy();
		$query = ' SELECT * '
			. ' FROM #__hotro '
		;
		$query = $query.$orderby;		
		return $query;
	}
	function getPagination(){
		if (empty($this->_pagination))
		{
			jimport('joomla.html.pagination');
			$this->_pagination = new JPagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
		}
		return $this->_pagination;
	}
	
	function getTotal()	{
		if (empty($this->_total))
		{
			$query = $this->_buildQuery();
			$this->_total = $this->_getListCount($query);
		}
		return $this->_total;
	}
	function getData()	{
		if (empty( $this->_data ))
		{
			$query = $this->_buildQuery();
			$this->_data = $this->_getList( $query );
		}
		return $this->_data;
	}
	function _buildContentOrderBy()	{
		global $mainframe, $option;
		$filter_order		= $mainframe->getUserStateFromRequest( $option.'filter_order','filter_order','ordering',	'cmd' );
		$filter_order_Dir	= $mainframe->getUserStateFromRequest( $option.'filter_order_Dir',	'filter_order_Dir',	'',				'word' );
		
		if (!in_array($filter_order, array('hotro_id','nickname1', 'ordering','parent_id', 'nickname2'))) {
			$filter_order = 'ordering';
		}
		if (!in_array(strtoupper($filter_order_Dir), array('ASC', 'DESC'))) {
			$filter_order_Dir = '';
		}
		if ($filter_order == 'ordering'){
			$orderby 	= ' ORDER BY parent_id '.$filter_order_Dir.' , ordering ';
		} else {
			$orderby 	= ' ORDER BY '.$filter_order.' '.$filter_order_Dir.' , ordering ';
		}
		return $orderby;
	}
}
?>
